﻿using System.Collections.Generic;
using System.Xml.Linq;
using Schema = QASPRibbon.RibbonSchema;

namespace QASPRibbon.Controls
{
    /// <summary>
    /// Represents a ContextualGroup control in the SharePoint Server Ribbon. 
    /// </summary>
    public class RibbonContextualGroup : RibbonElement
    {
        internal override string XmlTag
        {
            get { return Schema.ContextualGroup; }
        }

        internal override XElement AsXElement()
        {
            var groupElement = new XElement(XmlTag,
                    new XAttribute(Schema.Color, Color.ToString()),
                    new XAttribute(Schema.Command, Id + ".EnableContextualGroup"),
                    new XAttribute(Schema.Id, "Ribbon." + Id),
                    new XAttribute(Schema.Title, Title),
                    new XAttribute(Schema.Sequence, 502),
                    new XAttribute(Schema.ContextualGroupId, Id)
                );
            foreach (var tab in Tabs)
            {
                groupElement.Add(tab.AsXElement());
            }
            return groupElement;
        }

        ///<summary>
        /// An enumeration value that specifies a color scheme for the group.
        ///</summary>
        public RibbonContextualColor Color { get; set; }
        
        ///<summary>
        /// Collection of tab.
        ///</summary>
        public IEnumerable<RibbonTab> Tabs { get; set; }

        #region Constructors

        /// <summary>
        /// Creates and initializes a new instance of the RibbonContextualGroup.
        /// </summary>
        public RibbonContextualGroup()
        {
            Color = RibbonContextualColor.None;
        }

        /// <summary>
        /// Creates and initializes a new instance of the RibbonContextualGroup.
        /// </summary>
        /// <param name="id">Identifier</param>
        public RibbonContextualGroup(string id) : base(id)
        {
            Color = RibbonContextualColor.None;
        }

        /// <summary>
        /// Creates and initializes a new instance of the RibbonContextualGroup.
        /// </summary>
        /// <param name="id">Identifier</param>
        /// <param name="title">Title</param>
        public RibbonContextualGroup(string id, string title) : base(id, title)
        {
            Color = RibbonContextualColor.None;
        }

        #endregion
    }
}
